home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_08 / weber / sclfxln.asm < prev    next >
Encoding:
Assembly Source File  |  1994-06-11  |  5.3 KB  |  179 lines

  1. ;************************************************
  2. ;* function: int scale_fax_line(unsigned char *dest, unsigned char *src)
  3. ;* NOTE: The C code uses right rotates, this uses left rotates
  4. ;*      cuz they are easier in assembly.  The direction is not important
  5. ;*      just as long as you are consistent.
  6. ;************************************************/
  7. vector_end_line:                ;short jump way station
  8.         jmp     end_line
  9. public scale_fax_line
  10. scale_fax_line proc uses ds si di, dest: near ptr byte, src: near ptr byte
  11. ;int scale_fax_line(unsigned char *dest, unsigned char *src)
  12. ;   {
  13. ;   int y_repeat,x_repeat,i,bit;
  14. ;   unsigned int accum;
  15. ;   unsigned char byte;
  16. ;   unsigned char *start;
  17. ;   ROTATOR rotator;
  18.  
  19.         assume ds:nothing
  20.     ;* get line repeat value and rotate to next */
  21. ;   y_repeat = y_base + (y_rotator & 0x01);
  22. ;   _ror(y_rotator);
  23. ;   if (y_repeat)
  24. ;       {
  25.         mov     ax,word ptr cs:y_rotator
  26.         add     ax,ax
  27.         rcl     word ptr cs:y_rotator+2,1
  28.         adc     ax,0
  29.         mov     word ptr cs:y_rotator,ax
  30.         and     ax,1
  31.         add     al,cs:y_base
  32.         jnz     line_ok
  33.         jmp     no_line
  34. line_ok:
  35.         push    bp
  36.         push    ax
  37.     ;* if anything to do */
  38.         mov     si,ds                   ;large model data use lds and les
  39.         mov     es,si
  40.         mov     si,src
  41.         mov     di,dest
  42. ;       rotator = x_rotator;
  43.         mov     bx,word ptr cs:x_rotator
  44.         mov     dx,word ptr cs:x_rotator+2
  45. ;       for (i=source_width, accum=1, start=dest ; i > 0 ; i--, src++)
  46.         mov     bp,cs:source_width
  47.         mov     ah,1
  48.         push    di
  49. ;           {       ;* each byte in the source line */
  50. byte_loop:
  51.         dec     bp
  52.         js      vector_end_line
  53.         lodsb
  54. ;           if (*src)
  55.         or      al,al
  56.         jz      all_white
  57. ;               {   ;* if it has black bits */
  58. ;               for (bit=8, byte=*src ; bit > 0 ; bit--)
  59. ;                   {   ;* for each bit in the byte */
  60. ;                   x_repeat = x_base + (rotator & 1);
  61. ;                   _ror(rotator);      ;* get repeat count and rotate */
  62. ;                   while (x_repeat--)
  63. ;                       {               ;* for each repeat */
  64. ;                       accum <<= 1;    ;* copy bit into accumulator */
  65. ;                       accum += ((byte & 0x80) != 0);
  66. ;                       if (accum & 0x100)
  67. ;                           {           ;* output a byte and reset sentinel */
  68. ;                           *dest++ = (unsigned char) accum;
  69. ;                           accum = 1;
  70. ;                           }
  71. ;                       }
  72. ;                   byte <<= 1;
  73.         mov     cl,8
  74. bit_loop:
  75.         xor     ch,ch
  76.         add     bx,bx
  77.         adc     dx,dx
  78.         adc     ch,0
  79.         add     bl,ch
  80.         add     ch,cs:x_base
  81.         or      ch,ch
  82.         jz      bit_next
  83. bit_repeat:
  84.         cmp     al,80h
  85.         cmc
  86.         adc     ah,ah
  87.         jc      bit_update
  88. repeat_next:
  89.         dec     ch
  90.         jnz     bit_repeat
  91. bit_next:
  92.         add     al,al
  93.         dec     cl
  94.         jnz     bit_loop
  95.         jmp     short byte_loop
  96. bit_update:
  97.         xchg    al,ah
  98.         stosb
  99.         xchg    al,ah
  100.         mov     ah,1
  101.         jmp     short repeat_next
  102. ;                   }
  103. ;               }
  104. ;           else
  105. ;               {   ;* no black bits, just spin it out. */
  106. all_white:
  107.                 ;* how many repeats? */
  108. ;               x_repeat = bit_repeat_count + ((rotator & 0xff) > bit_repeat_pattern);
  109.         xor     cx,cx
  110.         cmp     cs:bit_repeat_pattern,dh
  111.         adc     cx,cs:bit_repeat_count
  112.                 ;* rotate by 8 */
  113. ;               rotator = (rotator << (PRECISION-8)) | (rotator >> 8);
  114.         xchg    bl,bh
  115.         xchg    bl,dl
  116.         xchg    bl,dh
  117.                 ;* do it */
  118. ;               while (x_repeat--)
  119. ;                   {
  120. ;                   accum <<= 1;
  121. ;                   if (accum & 0x100)
  122. ;                       {
  123. ;                       *dest++ = (unsigned char) accum;
  124. ;                       accum = 1;
  125. ;                       }
  126. ;                   }
  127.         jcxz    byte_loop
  128. white_loop:
  129.         add     ax,ax
  130.         jc      white_update
  131.         loop    white_loop
  132.         jmp     byte_loop
  133. white_update:
  134.         xchg    al,ah
  135.         stosb
  136.         xchg    al,ah
  137.         mov     ah,1
  138.         loop    white_loop
  139.         jmp     byte_loop
  140. ;               }
  141. ;           }
  142. ;       if (accum > 1)
  143. ;           {                       ;* handle fragment */
  144. ;           while ((accum & 0x100) == 0)
  145. ;               accum <<= 1;
  146. ;           *dest++ = (unsigned char) accum;
  147. ;           }
  148. end_line:
  149.         cmp     ah,1
  150.         jbe     no_fragment
  151. fragment_loop:
  152.         add     ah,ah
  153.         jnc     fragment_loop
  154.         stosb
  155. no_fragment:
  156. ;       while (dest < start + FAX_WIDTH)
  157. ;           {                       ;* white out tail */
  158. ;           *dest++ = 0;
  159. ;           }
  160. ;       }
  161.         pop     ax
  162.         sub     ax,di
  163.         add     ax,FAX_WIDTH
  164.         jle     no_tail
  165.         mov     cx,ax
  166.         xor     ax,ax
  167.         shr     cx,1
  168.         rep     stosw
  169.         adc     cx,0
  170.         rep     stosb
  171. no_tail:
  172. ;   return y_repeat;
  173.         pop     ax
  174.         pop     bp
  175. no_line:
  176.         ret
  177. ;   }
  178. scale_fax_line endp
  179.